#!/bin/bash
echo `date`
echo ' check_mysql.sh start'

function check(){
    process_name="mysql"

    # 指定要查询和杀死的进程名称
    pid=`ps -ef | grep $process_name | grep -v grep | awk '{print $2}'`

    if [ -z "$pid" ]; then
        echo "No process found with name $process_name"
        nohup /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariad --user=root &
    else
        # 杀死进程
        echo "success"
    fi
}

check

echo 'end'
